package com.sky.task;

import com.sky.constant.RedisConstant;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

@Component
public class ShopStatusTask {

    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    /**
     * 检查Redis是否存储店铺状态，若不存在设置店铺状态为0
     *
     */
    @Scheduled(cron = "0 * * * * ?")//每分钟执行一次
    public void checkShopStatus() {
        // 1.检查Redis是否存储店铺状态
        Integer shopStatus = (Integer)this.redisTemplate.opsForValue().get(RedisConstant.KEY);
        if (shopStatus == null) {
            // 2.不存在设置店铺状态为0
            this.redisTemplate.opsForValue().set(RedisConstant.KEY, 0);
        }
    }
}
